package flyWeightPattern;

public class Main {
    public static void main(String[] args) {
        Factory factory = new Factory();    //享元工厂

        ChessPiece horse = factory.getChessPiece("马");//创建享元类型--马
        horse.display(new Position(1, 1));

        ChessPiece elephant = factory.getChessPiece("象");//创建享元类型--象
        elephant.display(new Position(2, 2));

        ChessPiece horse2 = factory.getChessPiece("马");//创建享元类型--马
        horse2.display(new Position(3, 3));

        System.out.println(horse == horse2);    //true，享元模式的优势

    }
}
